package com.orifine.orm.type;



import com.orifine.orm.Information;
import com.orifine.orm.Type;
import com.orifine.orm.information.CharRandomInfo;
import com.orifine.orm.model.ColumnModel;

/**
 * 存放最大长度为 65,535 个字符的字符串。
 * @author Administrator
 *
 */
public class LongText extends Type {
	private String text;
	
	LongText() {
	}
	
	public LongText(String text){
		this.text = text;
	}
	
	@Override
	public String getScriptType(ColumnModel column) {
		if(column.getUnique().isUnique()){
			column.getUnique().isUnique(false);
			System.out.println("警告："+column.getField()+" 当前的数据类型是LONGTEXT,与@Unique注解冲突");
		}
		if(column.getDefault() == null){
			column.setDefault(null);
			System.out.println("警告："+column.getField()+" 当前的数据类型是LONGTEXT,与@Default注解冲突");
		}
		return "LONGTEXT";
	}
	
	public String toString(){
		return text;
	}

	@Override
	public String getScriptValue(ColumnModel column) {
		if(text == null) return "NULL";
		else return filterQuote(text);
	}
	
	public static final long MAX_LENGTH = 3221225471L;

	@Override
	public Information getDefaultInfo(ColumnModel column) {
		return new CharRandomInfo(column.getLength().getValue());
	}
}
